package com.tianqu.tms.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tianqu.tms.core.base.TmsEntity;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dao.TransMarketCodeDao;
import com.tianqu.tms.dto.TransMarketCodeDto;
/**
 * 交易票所属市场字典表
 * @author Administrator
 *
 */
public class TransMarketCode extends TmsEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6686187960933738871L;

	private int id;
	private String marketName;//市场名称
	private String taxpayerNo;//纳税人识别号
	private String address;//地址
	private String bank;//开户银行
	private String phone;//电话


	public static TransMarketCode getInstance() {
		TransMarketCode trans = new TransMarketCode();
		trans.setExisting(false);
		return trans;
	}	
	/**
	 * 根据交易票ID查询交易票信息
	 * @param id
	 * @return
	 * @throws TmsDaoException
	 */
	public TransMarketCode getTransMarketCodeInfo(String id) throws TmsDaoException
	{
		TransMarketCode entity = new TransMarketCode();
		TransMarketCodeDao uDao = (TransMarketCodeDao) TmsDao.getInstance(TmsDao.TMS_TRANSMARKET_CODE);
		TransMarketCodeDto dto = uDao.getTransMarketCodeInfo(id);
		if(dto!=null)
		{
			entity.setMarketName(dto.getMarketName());
			entity.setTaxpayerNo(dto.getTaxpayerNo());
			entity.setAddress(dto.getAddress());
			entity.setBank(dto.getBank());
			entity.setPhone(dto.getPhone());
		}else{
			return null;
		}
		return entity;
	}
	
	public List<TransMarketCodeDto> getTransMarketCodeInfoByPy(String py) throws TmsDaoException
	{
		TransMarketCode entity = new TransMarketCode();
		TransMarketCodeDao uDao = (TransMarketCodeDao) TmsDao.getInstance(TmsDao.TMS_TRANSMARKET_CODE);
		List<TransMarketCodeDto> r = uDao.getTransMarketCodeInfoByPy(py);
		return r;
	}
	/**
	 * 获取所有交易票信息
	 * @return
	 * @throws TmsDaoException
	 */
	@SuppressWarnings("unchecked")
	public List loadAllTransMarketCode() throws TmsDaoException
	{
		TransMarketCodeDao uDao = (TransMarketCodeDao) TmsDao.getInstance(TmsDao.TMS_TRANSMARKET_CODE);	
		List<TransMarketCodeDto> dtoList = uDao.loadAllTransMarketCode();
		List list = new ArrayList();// 用于存放会员信息
		Map map = null;
		for (int i = 0; i < dtoList.size(); i++) {
			TransMarketCodeDto dto = (TransMarketCodeDto) dtoList.get(i);
			map = new HashMap();
			map.put("marketId", dto.getId());
			map.put("marketName", dto.getMarketName());
			list.add(map);
		}
		if (list.size() == 0) {
			return null;
		}
		return list;
	}
	
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getMarketName() {
		return marketName;
	}

	public void setMarketName(String marketName) {
		this.marketName = marketName;
	}

	public String getTaxpayerNo() {
		return taxpayerNo;
	}

	public void setTaxpayerNo(String taxpayerNo) {
		this.taxpayerNo = taxpayerNo;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getBank() {
		return bank;
	}

	public void setBank(String bank) {
		this.bank = bank;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Override
	public void save() throws TmsDaoException, TmsException {
		// TODO Auto-generated method stub

	}

}
